import React from 'react'
import {BrowserRouter as Router,Switch,Route} from 'react-router-dom'
import RouteWithSubRoutes from './RouteWithSubRoutes'
import Bundle from './Bundle'

const Login = (props) => (
    <Bundle load={() => import('../components/Login')}>
        {(Login) => <Login {...props}/>}
    </Bundle>
);

const Home = (props)=>(
    <Bundle load={() => import('../components/Home')}>
        {(Login) => <Login {...props}/>}
    </Bundle>
);

const routes = [
    {
        path:'/',
        component:Home,
    }
];

const Root = () => (
    <Router>
        <Switch>
            <Route path="/login" component={Login}/>
            {routes.map((route, i) => (
                <RouteWithSubRoutes key={i} {...route}/>
            ))}
        </Switch>
    </Router>
);

export default Root